package com.jsg.sl651.enums;

import com.jsg.sl651.message.parser.Parser;
import com.jsg.sl651.message.parser.impl.DoubleParser;
import com.jsg.sl651.util.ByteUtil;
import lombok.Getter;

/**
 * 人工置数编码要素及标识
 */
@Getter
public enum ManuallyCodingElementsIdentifiers {
    SECTIONAL_AREA(new byte[]{'A','C'},"断面面积","断面面积",3, "m²", DataDefinitionType.BCD, DoubleParser.class),
    // Daily average temperature
    DAILY_AVERAGE_TEMPERATURE(new byte[]{'A','D'},"日平均气温","日平均气温",1, "℃", DataDefinitionType.BCD, DoubleParser.class),
    // daily maximum temperature
    DAILY_MAXIMUM_TEMPERATURE(new byte[]{'A','D','M'},"日最高气温","日最高气温",1, "℃", DataDefinitionType.BCD, DoubleParser.class),
    // daily minimum temperature
    DAILY_MINIMUM_TEMPERATURE(new byte[]{'A','D','N'},"日最低气温","日最低气温",1, "℃", DataDefinitionType.BCD, DoubleParser.class),
    // 瞬时气温
    INSTANTANEOUS_TEMPERATURE(new byte[]{'A','I'},"瞬时气温","瞬时气温",1, "℃", DataDefinitionType.BCD, DoubleParser.class),
    // 面积测法
    AREA_MEASUREMENT_METHOD(new byte[]{'A','S'},"面积测法","面积测法",0, "", DataDefinitionType.BCD, DoubleParser.class),
    ;
    private final String strKey;
    private final byte[] keyBytes;
    private final String name;
    private final String desc;
    // 精度
    private final int precision;
    private final String unit;
    private final DataDefinitionType dataDefinitionType;
    private final Class<? extends Parser<?>> parser;

    ManuallyCodingElementsIdentifiers(byte[] keyBytes,
                                      String name,
                                      String desc,
                                      int precision,
                                      String unit,
                                      DataDefinitionType dataDefinitionType,
                                      Class<? extends Parser<?>> parser) {
        this.strKey = toKeyStr(keyBytes);
        this.keyBytes = keyBytes;
        this.name = name;
        this.desc = desc;
        this.precision = precision;
        this.unit = unit;
        this.dataDefinitionType = dataDefinitionType;
        this.parser = parser;
    }


    private static String toKeyStr(byte[] keyBytes) {
        StringBuilder key = new StringBuilder();
        for (byte keyByte : keyBytes) {
            key.append((char) keyByte);
        }
        return key.toString();
    }

}
